package com.ruoyi.web.controller.common.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ErpStore;
import com.ruoyi.system.service.IErpStoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-16
 */
@RestController
@RequestMapping("/system/store")
public class ErpStoreController extends BaseController
{
    @Autowired
    private IErpStoreService erpStoreService;

    /**
     * 查询入库管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpStore erpStore)
    {
        // 原：数据分页
        startPage();
        List<ErpStore> list = erpStoreService.selectErpStoreList(erpStore);
        return getDataTable(list);



        /*解决方法：删除数据分页。但前端无法进行分页操作
        // 1. 查询所有数据（无分页）
        List<ErpStore> list = erpStoreService.selectErpStoreList(erpStore);

        // 2. 封装响应（保持原有结构）
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(list);
        rspData.setTotal(list.size()); // 或通过 countErpStore() 获取总数

        return rspData;

         */
    }

    /**
     * 导出入库管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:store:export')")
    @Log(title = "入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpStore erpStore)
    {
        List<ErpStore> list = erpStoreService.selectErpStoreList(erpStore);
        ExcelUtil<ErpStore> util = new ExcelUtil<ErpStore>(ErpStore.class);
        util.exportExcel(response, list, "入库管理数据");
    }

    /**
     * 获取入库管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:store:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(erpStoreService.selectErpStoreById(id));
    }

    /**
     * 新增入库管理
     */
//    @PreAuthorize("@ss.hasPermi('system:store:add')")
    @Log(title = "入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpStore erpStore)
    {
        return toAjax(erpStoreService.insertErpStore(erpStore));
    }

    /**
     * 修改入库管理
     */
//    @PreAuthorize("@ss.hasPermi('system:store:edit')")
    @Log(title = "入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpStore erpStore)
    {
        return toAjax(erpStoreService.updateErpStore(erpStore));
    }

    /**
     * 删除入库管理
     */
//    @PreAuthorize("@ss.hasPermi('system:store:remove')")
    @Log(title = "入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpStoreService.deleteErpStoreByIds(ids));
    }
}
